home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / 130_01.zip / G81.ASM < prev    next >
Assembly Source File  |  1993-06-01  |  9KB  |  253 lines

  1.         page    55
  2.         maclib  bds
  3.         maclib  cmac
  4.  
  5.         direct
  6.         define  fillb
  7.         define  fill
  8.         define  strrot
  9.         define  hi
  10.         define  lo
  11.         enddir
  12. ;
  13. ;********************************************************
  14. ;*                                                      *
  15. ;*              BDS-C Supplementary Library             *
  16. ;*                      release 2                       *
  17. ;*                                                      *
  18. ;*              Steve de Plater, Nov. 1980              *
  19. ;*                    66 Priam St.                      *
  20. ;*                    Chester Hill,                     *
  21. ;*                    NSW, 2162                         *
  22. ;*                    Australia                         *
  23. ;*              Phone: (02) 644 4009                    *
  24. ;*                                                      *
  25. ;*              This file: G81.ASM release 1            *
  26. ;*                                                      *
  27. ;********************************************************
  28. ;
  29. ;
  30. ;============================================================= 
  31. ;
  32. ; int fillb(a1,a2,c,mode)
  33. ;  char c;
  34. ;  int a1, a2, mode;
  35. ;
  36. ;   if (mode==0)
  37. ;     Fills memory from address a1 to address a2 (inclusive)
  38. ;     with the byte c.
  39. ;   else
  40. ;     Fills memory from address a1 for a2 bytes with byte c.
  41. ;
  42.         prelude fillb
  43.  
  44.         call    arghak
  45.         push    b
  46.  
  47.         lda     arg4            ;"from/to" or "from/count"
  48.         ora     a               ;"from/to" - jump
  49.         reloc   jz,fillb2
  50.         lhld    arg2            ;"COUNT" value
  51.         push    h               ;move it to
  52.         pop     b               ;BC
  53.         reloc   jmp,fillb4      ;and jump
  54.  
  55. fillb2: lhld    arg1            ;"FROM" address
  56.         mov     a,l             ;turn it
  57.         cma                     ;round
  58.         mov     e,a             ;into the DE pair
  59.         mov     a,h
  60.         cma
  61.         mov     d,a             ;to form "1's comp"
  62.         inx     d               ;and now "2's comp"
  63.         lhld    arg2            ;and now get "TO" addr
  64.         dad     d               ;ie "TO" - "FROM" = range
  65.         push    h               ;move it to
  66.         pop     b               ;BC (bytes to fill)
  67.         inx     b               ;include the end address too!
  68.  
  69. fillb4: lhld    arg1            ;"FROM" address
  70.         lda     arg3            ;byte to fill with
  71.         mov     e,a             ;just somewhere to put it!
  72.  
  73. fillb6: mov     m,a             ;and fill it in there!
  74.         inx     h               ;point to next fill address
  75.         dcx     b               ;one less to go!
  76.         mov     a,b
  77.         ora     c               ;finished ?
  78.         reloc   jz,fillb8       ;yes - jump
  79.         mov     a,e             ;get fill byte again
  80.         reloc   jmp,fillb6      ;and fill with it
  81.  
  82. fillb8: pop     b               ;all over
  83.         ret
  84.  
  85.         postlude fillb
  86. ;
  87. ;============================================================= 
  88. ;
  89. ; char *fill(saddr,eaddr,string,opt)
  90. ;   char *string;
  91. ;
  92. ;   If (opt==0)
  93. ;     Fills a contiguous block of RAM starting at saddr and 
  94. ;     ending at eaddr with the string pointed to by "string".
  95. ;   else
  96. ;     Fills a contiguous block of RAM starting at saddr of
  97. ;     length eaddr bytes with the string pointed to.
  98. ;
  99. ;   The string is reused until the fill is complete.
  100. ;   Returns the address of the fill string.
  101. ;
  102.         prelude fill
  103.  
  104.         call    arghak
  105.         push    b
  106.  
  107.         lda     arg4            ;"from/to" or "from/count"
  108.         ora     a
  109.         reloc   jz,fill02       ;"from/to" - jump
  110.         lhld    arg2            ;get "COUNT"
  111.         push    h               ;and move to
  112.         pop     b               ;BC
  113.         reloc   jmp,fill04      ;then jump
  114.  
  115. fill02: lhld    arg1            ;"FROM" address
  116.         mov     a,l             ;turn it
  117.         cma                     ;round
  118.         mov     e,a             ;into the DE pair
  119.         mov     a,h
  120.         cma
  121.         mov     d,a             ;to form "1's comp"
  122.         inx     d               ;and now "2's comp"
  123.         lhld    arg2            ;and now get "TO" addr
  124.         dad     d               ;ie "TO" - "FROM" = range
  125.         push    h               ;move it to
  126.         pop     b               ;BC (bytes to fill)
  127.         inx     b               ;include the end address too!
  128.  
  129. fill04: lhld    arg1            ;"FROM" address
  130.         xchg                    ;to DE
  131.         lhld    arg3            ;pointer to the "fill string"
  132.         mov     a,m             ;get first char to fill with
  133.         ora     a               ;null string ?
  134.         reloc   jz,fill08       ;if so then quit
  135.  
  136. fill06: stax    d               ;and fill it in there!
  137.         inx     d               ;point to next fill address
  138.         inx     h               ;and next "fill string" char
  139.         dcx     b               ;one less to go!
  140.         mov     a,b
  141.         ora     c               ;finished ?
  142.         reloc   jz,fill08       ;yes - jump
  143.         mov     a,m             ;get the next char to fill with
  144.         ora     a               ;is it a 0 (end of string)
  145.         reloc   jnz,fill06      ;no - fill with it then
  146.         lhld    arg3            ;back to the start of string
  147.         mov     a,m             ;get the first char
  148.         reloc   jmp,fill06      ;and fill with it
  149.  
  150. fill08: lhld    arg3            ;return addr of the fill str 
  151.         pop     b               ;all over
  152.         ret
  153.  
  154.         postlude fill
  155. ;
  156. ;==============================================================
  157. ;
  158. ; char *strrot(mode,s)
  159. ;   char *s;
  160. ;
  161. ;    Rotates the string (end around) pointed to by "s".
  162. ;    If mode==0 then rotate LEFT, and
  163. ;    if mode<>0 then rotate RIGHT.
  164. ;    Returns the address of the string.
  165. ;
  166.         prelude strrot
  167.  
  168.         call    arghak
  169.         push    b
  170.  
  171.         lhld    arg2            ;point to string
  172.         push    h
  173.         pop     d               ;in DE as well
  174.         inx     d               ;and point ahead one
  175.         mvi     c,0             ;a counter to zero!
  176.         lda     arg1            ;get MODE switch
  177.         ora     a               ;rotate left ?
  178.         reloc   jnz,strr06      ;no - jump
  179.  
  180.         mov     a,m             ;get char to rotate
  181.         mov     b,a             ;and save it
  182. strr02: ldax    d               ;get char
  183.         ora     a               ;have we reached end of str
  184.         reloc   jz,strr04       ;yes - jump
  185.         mov     m,a             ;rotate the char
  186.         inx     h               ;next please
  187.         inx     d
  188.         reloc   jmp,strr02      ;and back for more
  189. strr04: mov     a,b             ;"the first shall be last.."
  190.         mov     m,a
  191.         reloc   jmp,strr14
  192.  
  193. strr06: mov     a,m             ;first scan for end
  194.         inx     h
  195.         inr     c               ;chars in string
  196.         ora     a               ;there yet ?
  197.         reloc   jnz,strr06      ;no - back we go
  198.         dcx     h               ;point back to the null
  199.         dcx     h               ;and then to last char
  200.         dcr     c               ;we don't count the null
  201.         push    h               ;and copy
  202.         pop     d               ;to DE
  203.         dcx     d               ;back one more
  204.         mov     a,m             ;the end char to save
  205.         mov     b,a             ;in B
  206. strr10: dcr     c               ;have we rotated enough ?
  207.         reloc   jz,strr12       ;yes - jump
  208.         ldax    d               ;get char to rotate
  209.         mov     m,a             ;and rotate it!
  210.         dcx     h               ;back one more
  211.         dcx     d
  212.         reloc   jmp,strr10      ;next please
  213. strr12: mov     a,b             ;".and the last shall be first"
  214.         mov     m,a
  215. strr14: lhld    arg2            ;return string address
  216.         pop     b
  217.         ret
  218.  
  219.         postlude strrot
  220. ;
  221. ;
  222. ;============================================================= 
  223. ;
  224. ; int hi(i)
  225. ;  int i;
  226. ;
  227. ;   Returns the high byte of i.
  228. ;
  229.         prelude hi
  230.  
  231.         call    ma1toh
  232.         mov     l,h
  233.         mvi     h,0
  234.         ret
  235.  
  236.         postlude hi
  237. ;
  238. ;============================================================= 
  239. ;
  240. ; int lo(i)
  241. ;  int i;
  242. ;
  243. ;   Returns the low byte of i.
  244. ;
  245.         prelude lo
  246.  
  247.         call    ma1toh
  248.         mvi     h,0
  249.         ret
  250.  
  251.         postlude lo
  252. ;
  253. low byte of i.